import 'package:baselib/utils/image_util.dart';
import 'package:baselib/widgets/comm_app_bar.dart';
import 'package:baselib/widgets/comm_textfield.dart';
import 'package:baselib/widgets/gradient_card_view.dart';
import 'package:baselib/widgets/gradient_text_widget.dart';
import 'package:baselib/widgets/inkwell_button.dart';
import 'package:baselib/widgets/refresh_util.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:framelib/utils/color_util.dart';
import 'package:framelib/utils/drawable_util.dart';
import 'package:framelib/utils/px_util.dart';
import 'package:framelib/utils/string_util.dart';
import 'package:framelib/widgets/comm_widget_manager.dart';
import 'package:framelib/widgets/main_gradient_button.dart';
import 'package:framelib/widgets/page_widget.dart';
import 'package:get/get.dart';
import 'package:module_business/module_index/viewmodel/room_admins_view_model.dart';
import 'package:module_business/module_index/viewmodel/room_block_list_view_model.dart';
import 'package:module_business/module_index/viewmodel/room_forbidden_list_view_model.dart';
import 'package:module_business/module_index/viewmodel/room_release_notification_view_model.dart';
import 'package:module_business/module_index/viewmodel/room_set_view_model.dart';
/**
 * 房间设置ForbiddenList主页
 */
class RoomForbiddenListPage extends GetWidget<RoomForbiddenListViewModel> {
  const RoomForbiddenListPage({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return PageWidget.build(
        builder: (RoomForbiddenListViewModel model){
          return PageWidget.PageScaffoldWidget(
            isShowBg: true,
            appBar: CommAppBar(
              backgroundColor: ColorUtil.instance.color_transparent,
              titleStr: StringUtil.instance.Forbidden_List,
              titleTextStyle: TextStyle(
                fontSize: PxUtil.instance.px_18,
                color: ColorUtil.instance.color_white,
                fontWeight: FontWeight.bold
              ),
            ),
            body: Container(
              width: PxUtil.instance.screenWidth,
              height: PxUtil.instance.screenHeight-PxUtil.instance.statusBarHeight
                  -PxUtil.instance.appBarHeight,
              padding: EdgeInsets.only(
                left: PxUtil.instance.px_15,
                right: PxUtil.instance.px_15,
              ),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Expanded(child: RefreshUtil.init(
                    model.refreshController,
                        ()=>model.onRefresh(pageCur: model?.page=1),
                        ()=>model.onRefresh(pageCur: model?.page+1),
                    _buildListUi(model),
                    physics: ClampingScrollPhysics(),
                    loadStatus: model?.loadStatus,
                    enablePullDown: true,
                    enablePullUp: true,
                    isCanMoreData: model?.isCanMoreData??true,
                    onReFreshFunction:()=>model.onRefresh(pageCur: model?.page=1),
                  ))
                ],
              ),
            ),
          );
        }
    );
  }

  Widget _buildListUi(RoomForbiddenListViewModel model) {
    return ListView.builder(
        shrinkWrap: true,
        itemCount: model.chatRoomForbiddenList?.length??0,
        itemBuilder: (BuildContext context,int index){
          var chatRoomAdmin = model.chatRoomForbiddenList[index];
          return Container(
            padding: EdgeInsets.only(
              top: PxUtil.instance.px_12,
              bottom: PxUtil.instance.px_12,
            ),
            decoration: BoxDecoration(
                border: Border(
                    bottom: BorderSide(
                        color: ColorUtil.instance.color_879d9d9d,
                        width: PxUtil.instance.px_0d5
                    )
                )
            ),
            child: Row(
              children: [
                CommWidgetManager.buildCicleImagWidget(
                  chatRoomAdmin?.icon ?? '',
                  placeholder: DrawableUtil.instance.icon_default_head,
                  width: PxUtil.instance.px_56,
                  height: PxUtil.instance.px_56,
                  roundRadius: PxUtil.instance.px_28,
                  backgroundColor: ColorUtil.instance.color_f2f2f2,
                  padding: EdgeInsets.only(),
                  margin: EdgeInsets.only(),
                ),
                SizedBox(width: PxUtil.instance.px_16,),
                Expanded(child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      chatRoomAdmin?.nickname??'',
                      style: TextStyle(
                          fontWeight: FontWeight.w500,
                          color: ColorUtil.instance.color_white,
                          fontSize: PxUtil.instance.px_15
                      ),
                    ),
                    GradientCardView(
                        margin: EdgeInsets.only(
                            top: PxUtil.instance.px_10
                        ),
                        padding: EdgeInsets.only(
                          left: PxUtil.instance.px_8,
                          right: PxUtil.instance.px_8,
                          top: PxUtil.instance.px_1,
                          bottom: PxUtil.instance.px_1,
                        ),
                        borderRadius: BorderRadius.circular(PxUtil.instance.px_2),
                        elevation: PxUtil.instance.px_0,
                        child: Text(
                          'Lv${chatRoomAdmin?.vipFlag??0}',
                          style: TextStyle(
                              fontWeight: FontWeight.bold,
                              color: ColorUtil.instance.color_white,
                              fontSize: PxUtil.instance.px_13
                          ),
                        )
                    )
                  ],
                )),
                Visibility(
                    visible: model.isHasPermission(),
                    child: InkWellButton(
                      onPressed: ()=>model.unBindAdmin(index),
                      child: Container(
                        child: ImagesUtil.loadAssetImage(
                            DrawableUtil.instance.icon_admin_unbind,
                            width: PxUtil.instance.px_22,
                            fit: BoxFit.fitWidth
                        ),
                      ),
                    ))
              ],
            ),
          );
        }
    );
  }
}
